package com.auxgroup.smarthome.vo;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by niuGuangzhe on 2017/8/1.
 */
public class AppPeakValleyVo {

    private String peakValleyId;

    private String deviceId;

    private Integer peakStartHour;

    private Integer peakStartMinute;

    private Integer peakEndHour;

    private Integer peakEndMinute;

    private Integer valleyStartHour;

    private Integer valleyStartMinute;

    private Integer valleyEndHour;

    private Integer valleyEndMinute;

    private Boolean on;

    public String getPeakValleyId() {
        return peakValleyId;
    }

    public void setPeakValleyId(String peakValleyId) {
        this.peakValleyId = peakValleyId;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public Integer getPeakStartHour() {
        return peakStartHour;
    }

    public void setPeakStartHour(Integer peakStartHour) {
        this.peakStartHour = peakStartHour;
    }

    public Integer getPeakStartMinute() {
        return peakStartMinute;
    }

    public void setPeakStartMinute(Integer peakStartMinute) {
        this.peakStartMinute = peakStartMinute;
    }

    public Integer getPeakEndHour() {
        return peakEndHour;
    }

    public void setPeakEndHour(Integer peakEndHour) {
        this.peakEndHour = peakEndHour;
    }

    public Integer getPeakEndMinute() {
        return peakEndMinute;
    }

    public void setPeakEndMinute(Integer peakEndMinute) {
        this.peakEndMinute = peakEndMinute;
    }

    public Integer getValleyStartHour() {
        return valleyStartHour;
    }

    public void setValleyStartHour(Integer valleyStartHour) {
        this.valleyStartHour = valleyStartHour;
    }

    public Integer getValleyStartMinute() {
        return valleyStartMinute;
    }

    public void setValleyStartMinute(Integer valleyStartMinute) {
        this.valleyStartMinute = valleyStartMinute;
    }

    public Integer getValleyEndHour() {
        return valleyEndHour;
    }

    public void setValleyEndHour(Integer valleyEndHour) {
        this.valleyEndHour = valleyEndHour;
    }

    public Integer getValleyEndMinute() {
        return valleyEndMinute;
    }

    public void setValleyEndMinute(Integer valleyEndMinute) {
        this.valleyEndMinute = valleyEndMinute;
    }

    public Boolean getOn() {
        return on;
    }

    public void setOn(Boolean on) {
        this.on = on;
    }

    /**
     * 是否是峰
     * @param datetime
     * @return
     */
    public boolean isPeak(String datetime){
        return checkTime(datetime,peakStartHour,peakEndHour);
    }

    /**
     * 是否是谷
     * @param datetime
     * @return
     */
    public boolean isValley(String datetime){
        return checkTime(datetime,valleyStartHour,valleyEndHour);
    }

    public boolean checkTime(String datetime,Integer startHour,Integer endHour){
        Date date = strToDate(datetime);
        if(date == null) return false;
        Calendar.getInstance().setTime(date);
        int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
        return hour >= startHour && hour <= endHour;
    }

    public Date strToDate(String str) {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHH");
        Date date = null;
        try {
            date = format.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}
